package com.hnhs.enums;

import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.Optional;

public enum ProdustStatus {
    ONLINE(0,"上线"),
    OFFLINE(1,"下线"),
    DISABLE(10,"禁售");

    @Getter
    @Setter
    private Integer code;
    @Getter
    @Setter
    private String msg;

    ProdustStatus(Integer code,String msg){
        this.code=code;
        this.msg=msg;
    }
    public static ProdustStatus findByCode(Integer code){
        if (code == null){
            return null;
        }
        //你要传递过的枚举
        // Optional 空处理函数
        Optional<ProdustStatus> first = Arrays.stream(ProdustStatus.values()).filter(item ->
                item.getCode().equals(code)).findFirst();
        if(first.isPresent()){
            return first.get();
        }
        //如果没有值 就直接放回null
        return first.orElse(null);
    }



}
